* [Qemu-devel] [PULL v2 00/23] Block layer patches
@ 2015-09-14 15:25 Kevin Wolf
2015-09-14 15:25 ` [Qemu-devel] [PULL v2 20/23] qcow2: Make size_to_clusters() return uint64_t Kevin Wolf
2015-09-15 9:34 ` [Qemu-devel] [PULL v2 00/23] Block layer patches Peter Maydell
0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2015-09-14 15:25 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
The following changes since commit 2b750d9d261bda7f75b39dfc1e1e5f22502929d5:
Merge remote-tracking branch 'remotes/aurel/tags/pull-sh4-next-20150913' into staging (2015-09-14 10:46:38 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 2ac01520be8717f3492b10a083c3e0e22cb52cda:
qcow2: Make qcow2_alloc_bytes() more explicit (2015-09-14 16:51:37 +0200)
----------------------------------------------------------------
Block layer patches (v2)
----------------------------------------------------------------
Kevin Wolf (14):
qcow2: Rename BDRVQcowState to BDRVQcow2State
block: Allow specifying driver-specific options to reopen
qemu-io: Remove duplicate 'open' error message
qemu-io: Add command 'reopen'
qcow2: Improve error message
qcow2: Factor out qcow2_update_options()
qcow2: Move qcow2_update_options() call up
qcow2: Move rest of option handling to qcow2_update_options()
qcow2: Leave s unchanged on qcow2_update_options() failure
qcow2: Fix memory leak in qcow2_update_options() error path
qcow2: Make qcow2_update_options() suitable for transactions
qcow2: Support updating driver-specific options in reopen
qemu-iotests: Reopen qcow2 with lazy-refcounts change
qemu-iotests: More qcow2 reopen tests
Max Reitz (8):
block: Always pass NULL as drv for bdrv_open()
block: Drop drv parameter from bdrv_open()
block: Drop drv parameter from bdrv_open_inherit()
block: Drop drv parameter from bdrv_fill_options()
block: Drop bdrv_find_whitelisted_format()
qcow2: Make size_to_clusters() return uint64_t
iotests: Add test for checking large image files
qcow2: Make qcow2_alloc_bytes() more explicit
Radoslav Gerganov (1):
vmdk: Fix next_cluster_sector for compressed write
block.c | 150 +++++++-------
block/block-backend.c | 2 +-
block/commit.c | 4 +-
block/parallels.c | 2 +-
block/qcow.c | 2 +-
block/qcow2-cache.c | 14 +-
block/qcow2-cluster.c | 76 +++----
block/qcow2-refcount.c | 76 ++++---
block/qcow2-snapshot.c | 20 +-
block/qcow2.c | 486 +++++++++++++++++++++++++++++----------------
block/qcow2.h | 26 +--
block/qed.c | 2 +-
block/sheepdog.c | 5 +-
block/vdi.c | 2 +-
block/vhdx.c | 2 +-
block/vmdk.c | 15 +-
block/vpc.c | 2 +-
block/vvfat.c | 8 +-
blockdev.c | 72 +++----
include/block/block.h | 9 +-
qemu-io-cmds.c | 90 +++++++++
qemu-io.c | 1 -
tests/qemu-iotests/039 | 27 +++
tests/qemu-iotests/039.out | 18 ++
tests/qemu-iotests/137 | 145 ++++++++++++++
tests/qemu-iotests/137.out | 42 ++++
tests/qemu-iotests/138 | 73 +++++++
tests/qemu-iotests/138.out | 9 +
tests/qemu-iotests/group | 2 +
29 files changed, 973 insertions(+), 409 deletions(-)
create mode 100755 tests/qemu-iotests/137
create mode 100644 tests/qemu-iotests/137.out
create mode 100755 tests/qemu-iotests/138
create mode 100644 tests/qemu-iotests/138.out
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PULL v2 20/23] qcow2: Make size_to_clusters() return uint64_t
2015-09-14 15:25 [Qemu-devel] [PULL v2 00/23] Block layer patches Kevin Wolf
@ 2015-09-14 15:25 ` Kevin Wolf
2015-09-15 9:34 ` [Qemu-devel] [PULL v2 00/23] Block layer patches Peter Maydell
1 sibling, 0 replies; 3+ messages in thread
From: Kevin Wolf @ 2015-09-14 15:25 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
From: Max Reitz <mreitz@redhat.com>
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).
Cc: qemu-stable <qemu-stable@nongnu.org>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qcow2-cluster.c | 28 ++++++++++++++++++----------
block/qcow2-refcount.c | 12 ++++++++----
block/qcow2.h | 6 +++---
3 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 412ee27..6ede629 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -298,7 +298,7 @@ fail:
* as contiguous. (This allows it, for example, to stop at the first compressed
* cluster which may require a different handling)
*/
-static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
+static int count_contiguous_clusters(int nb_clusters, int cluster_size,
uint64_t *l2_table, uint64_t stop_flags)
{
int i;
@@ -321,7 +321,7 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
return i;
}
-static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_table)
+static int count_contiguous_free_clusters(int nb_clusters, uint64_t *l2_table)
{
int i;
@@ -495,6 +495,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
if (nb_needed > nb_available) {
nb_needed = nb_available;
}
+ assert(nb_needed <= INT_MAX);
*cluster_offset = 0;
@@ -530,6 +531,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
*cluster_offset = be64_to_cpu(l2_table[l2_index]);
+
+ /* nb_needed <= INT_MAX, thus nb_clusters <= INT_MAX, too */
nb_clusters = size_to_clusters(s, nb_needed << 9);
ret = qcow2_get_cluster_type(*cluster_offset);
@@ -960,7 +963,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
int l2_index;
uint64_t cluster_offset;
uint64_t *l2_table;
- unsigned int nb_clusters;
+ uint64_t nb_clusters;
unsigned int keep_clusters;
int ret;
@@ -979,6 +982,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
l2_index = offset_to_l2_index(s, guest_offset);
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
+ assert(nb_clusters <= INT_MAX);
/* Find L2 entry for the first involved cluster */
ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);
@@ -1061,7 +1065,7 @@ out:
* restarted, but the whole request should not be failed.
*/
static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset,
- uint64_t *host_offset, unsigned int *nb_clusters)
+ uint64_t *host_offset, uint64_t *nb_clusters)
{
BDRVQcow2State *s = bs->opaque;
@@ -1079,7 +1083,7 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset,
*host_offset = cluster_offset;
return 0;
} else {
- int ret = qcow2_alloc_clusters_at(bs, *host_offset, *nb_clusters);
+ int64_t ret = qcow2_alloc_clusters_at(bs, *host_offset, *nb_clusters);
if (ret < 0) {
return ret;
}
@@ -1115,7 +1119,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
int l2_index;
uint64_t *l2_table;
uint64_t entry;
- unsigned int nb_clusters;
+ uint64_t nb_clusters;
int ret;
uint64_t alloc_cluster_offset;
@@ -1133,6 +1137,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
l2_index = offset_to_l2_index(s, guest_offset);
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
+ assert(nb_clusters <= INT_MAX);
/* Find L2 entry for the first involved cluster */
ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);
@@ -1426,7 +1431,8 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
* clusters.
*/
static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
- unsigned int nb_clusters, enum qcow2_discard_type type, bool full_discard)
+ uint64_t nb_clusters, enum qcow2_discard_type type,
+ bool full_discard)
{
BDRVQcow2State *s = bs->opaque;
uint64_t *l2_table;
@@ -1441,6 +1447,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
/* Limit nb_clusters to one L2 table */
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
+ assert(nb_clusters <= INT_MAX);
for (i = 0; i < nb_clusters; i++) {
uint64_t old_l2_entry;
@@ -1503,7 +1510,7 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
{
BDRVQcow2State *s = bs->opaque;
uint64_t end_offset;
- unsigned int nb_clusters;
+ uint64_t nb_clusters;
int ret;
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
@@ -1545,7 +1552,7 @@ fail:
* clusters.
*/
static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
- unsigned int nb_clusters)
+ uint64_t nb_clusters)
{
BDRVQcow2State *s = bs->opaque;
uint64_t *l2_table;
@@ -1560,6 +1567,7 @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
/* Limit nb_clusters to one L2 table */
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
+ assert(nb_clusters <= INT_MAX);
for (i = 0; i < nb_clusters; i++) {
uint64_t old_offset;
@@ -1584,7 +1592,7 @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors)
{
BDRVQcow2State *s = bs->opaque;
- unsigned int nb_clusters;
+ uint64_t nb_clusters;
int ret;
/* The zero flag is only supported by version 3 and newer */
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index b780bb9..a49d59e 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -875,8 +875,8 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size)
return offset;
}
-int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
- int nb_clusters)
+int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
+ int64_t nb_clusters)
{
BDRVQcow2State *s = bs->opaque;
uint64_t cluster_index, refcount;
@@ -1259,7 +1259,7 @@ static size_t refcount_array_byte_size(BDRVQcow2State *s, uint64_t entries)
static int realloc_refcount_array(BDRVQcow2State *s, void **array,
int64_t *size, int64_t new_size)
{
- size_t old_byte_size, new_byte_size;
+ int64_t old_byte_size, new_byte_size;
void *new_ptr;
/* Round to clusters so the array can be directly written to disk */
@@ -1275,13 +1275,17 @@ static int realloc_refcount_array(BDRVQcow2State *s, void **array,
assert(new_byte_size > 0);
+ if (new_byte_size > SIZE_MAX) {
+ return -ENOMEM;
+ }
+
new_ptr = g_try_realloc(*array, new_byte_size);
if (!new_ptr) {
return -ENOMEM;
}
if (new_byte_size > old_byte_size) {
- memset((void *)((uintptr_t)new_ptr + old_byte_size), 0,
+ memset((char *)new_ptr + old_byte_size, 0,
new_byte_size - old_byte_size);
}
diff --git a/block/qcow2.h b/block/qcow2.h
index 61f1b57..d700bf1 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -415,7 +415,7 @@ static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
return offset & (s->cluster_size - 1);
}
-static inline int size_to_clusters(BDRVQcow2State *s, int64_t size)
+static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
{
return (size + (s->cluster_size - 1)) >> s->cluster_bits;
}
@@ -509,8 +509,8 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
enum qcow2_discard_type type);
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
-int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
- int nb_clusters);
+int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
+ int64_t nb_clusters);
int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
void qcow2_free_clusters(BlockDriverState *bs,
int64_t offset, int64_t size,
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PULL v2 00/23] Block layer patches
2015-09-14 15:25 [Qemu-devel] [PULL v2 00/23] Block layer patches Kevin Wolf
2015-09-14 15:25 ` [Qemu-devel] [PULL v2 20/23] qcow2: Make size_to_clusters() return uint64_t Kevin Wolf
@ 2015-09-15 9:34 ` Peter Maydell
1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2015-09-15 9:34 UTC (permalink / raw)
To: Kevin Wolf; +Cc: QEMU Developers, Qemu-block
On 14 September 2015 at 16:25, Kevin Wolf <kwolf@redhat.com> wrote:
> The following changes since commit 2b750d9d261bda7f75b39dfc1e1e5f22502929d5:
>
> Merge remote-tracking branch 'remotes/aurel/tags/pull-sh4-next-20150913' into staging (2015-09-14 10:46:38 +0100)
>
> are available in the git repository at:
>
>
> git://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to 2ac01520be8717f3492b10a083c3e0e22cb52cda:
>
> qcow2: Make qcow2_alloc_bytes() more explicit (2015-09-14 16:51:37 +0200)
>
> ----------------------------------------------------------------
> Block layer patches (v2)
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-15 9:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14 15:25 [Qemu-devel] [PULL v2 00/23] Block layer patches Kevin Wolf
2015-09-14 15:25 ` [Qemu-devel] [PULL v2 20/23] qcow2: Make size_to_clusters() return uint64_t Kevin Wolf
2015-09-15 9:34 ` [Qemu-devel] [PULL v2 00/23] Block layer patches Peter Maydell
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).