diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2017-05-04 13:44:32 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2017-05-04 13:44:32 +0100 |
commit | 12a95f320a36ef66f724a49bb05e4fb553ac5dbe (patch) | |
tree | 2cc75fc4825c637ae96a9ae779f14c4af5936325 /block/qcow2.c | |
parent | e619b14746e5d8c0e53061661fd0e1da01fd4d60 (diff) | |
parent | 5fc0fe383fff318b38291dcdf2cf38e329ec232a (diff) | |
download | qemu-12a95f320a36ef66f724a49bb05e4fb553ac5dbe.zip qemu-12a95f320a36ef66f724a49bb05e4fb553ac5dbe.tar.gz qemu-12a95f320a36ef66f724a49bb05e4fb553ac5dbe.tar.bz2 |
Merge remote-tracking branch 'kwolf/tags/for-upstream' into staging
Block layer patches
# gpg: Signature made Fri 28 Apr 2017 09:20:17 PM BST
# gpg: using RSA key 0x7F09B272C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6
* kwolf/tags/for-upstream: (34 commits)
progress: Show current progress on SIGINFO
iotests: fix exclusion option
iotests: clarify help text
qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed
qemu-img: improve convert_iteration_sectors()
block: assert no image modification under BDRV_O_INACTIVE
block: fix obvious coding style mistakes in block_int.h
qcow2: Allow discard of final unaligned cluster
block: Add .bdrv_truncate() error messages
block: Add errp to BD.bdrv_truncate()
block: Add errp to b{lk,drv}_truncate()
block/vhdx: Make vhdx_create() always set errp
qemu-img: Document backing options
qemu-img/convert: Move bs_n > 1 && -B check down
qemu-img/convert: Use @opts for one thing only
block: fix alignment calculations in bdrv_co_do_zero_pwritev
block: Do not unref bs->file on error in BD's open
iotests: 109: Filter out "len" of failed jobs
iotests: Fix typo in 026
Issue a deprecation warning if the user specifies the "-hdachs" option.
...
Message-id: 1493411622-5343-1-git-send-email-kwolf@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index 6a92d2e..5c1573c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2294,9 +2294,9 @@ static int qcow2_create2(const char *filename, int64_t total_size, } /* Okay, now that we have a valid image, let's give it the right size */ - ret = blk_truncate(blk, total_size); + ret = blk_truncate(blk, total_size, errp); if (ret < 0) { - error_setg_errno(errp, -ret, "Could not resize image"); + error_prepend(errp, "Could not resize image: "); goto out; } @@ -2515,7 +2515,12 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs, if (!QEMU_IS_ALIGNED(offset | count, s->cluster_size)) { assert(count < s->cluster_size); - return -ENOTSUP; + /* Ignore partial clusters, except for the special case of the + * complete partial cluster at the end of an unaligned file */ + if (!QEMU_IS_ALIGNED(offset, s->cluster_size) || + offset + count != bs->total_sectors * BDRV_SECTOR_SIZE) { + return -ENOTSUP; + } } qemu_co_mutex_lock(&s->lock); @@ -2525,32 +2530,33 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs, return ret; } -static int qcow2_truncate(BlockDriverState *bs, int64_t offset) +static int qcow2_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVQcow2State *s = bs->opaque; int64_t new_l1_size; int ret; if (offset & 511) { - error_report("The new size must be a multiple of 512"); + error_setg(errp, "The new size must be a multiple of 512"); return -EINVAL; } /* cannot proceed if image has snapshots */ if (s->nb_snapshots) { - error_report("Can't resize an image which has snapshots"); + error_setg(errp, "Can't resize an image which has snapshots"); return -ENOTSUP; } /* shrinking is currently not supported */ if (offset < bs->total_sectors * 512) { - error_report("qcow2 doesn't support shrinking images yet"); + error_setg(errp, "qcow2 doesn't support shrinking images yet"); return -ENOTSUP; } new_l1_size = size_to_l1(s, offset); ret = qcow2_grow_l1_table(bs, new_l1_size, true); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to grow the L1 table"); return ret; } @@ -2559,6 +2565,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset) ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), &offset, sizeof(uint64_t)); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to update the image size"); return ret; } @@ -2584,7 +2591,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset = bdrv_getlength(bs->file->bs); - return bdrv_truncate(bs->file, cluster_offset); + return bdrv_truncate(bs->file, cluster_offset, NULL); } buf = qemu_blockalign(bs, s->cluster_size); @@ -2674,6 +2681,7 @@ fail: static int make_completely_empty(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque; + Error *local_err = NULL; int ret, l1_clusters; int64_t offset; uint64_t *new_reftable = NULL; @@ -2798,8 +2806,10 @@ static int make_completely_empty(BlockDriverState *bs) goto fail; } - ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size); + ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size, + &local_err); if (ret < 0) { + error_report_err(local_err); goto fail; } @@ -3273,9 +3283,10 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, return ret; } - ret = blk_truncate(blk, new_size); + ret = blk_truncate(blk, new_size, &local_err); blk_unref(blk); if (ret < 0) { + error_report_err(local_err); return ret; } } |