diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2010-04-28 11:36:11 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2010-05-03 10:07:32 +0200 |
commit | 419b19d9b427fad5ff2fa886d8cc217f7acee18c (patch) | |
tree | a119877c837b2f6e053823001c111f12a3388c31 /block/qcow2.h | |
parent | 003fad6e2cae5311d3aea996388c90e3ab17de90 (diff) | |
download | qemu-419b19d9b427fad5ff2fa886d8cc217f7acee18c.zip qemu-419b19d9b427fad5ff2fa886d8cc217f7acee18c.tar.gz qemu-419b19d9b427fad5ff2fa886d8cc217f7acee18c.tar.bz2 |
qcow2: Implement bdrv_truncate() for growing images
This patch adds the ability to grow qcow2 images in-place using
bdrv_truncate(). This enables qemu-img resize command support for
qcow2.
Snapshots are not supported and bdrv_truncate() will return -ENOTSUP.
The notion of resizing an image with snapshots could lead to confusion:
users may expect snapshots to remain unchanged, but this is not possible
with the current qcow2 on-disk format where the header.size field is
global instead of per-snapshot. Others may expect snapshots to change
size along with the current image data. I think it is safest to not
support snapshots and perhaps add behavior later if there is a
consensus.
Backing images continue to work. If the image is now larger than its
backing image, zeroes are read when accessing beyond the end of the
backing image.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.h')
-rw-r--r-- | block/qcow2.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/block/qcow2.h b/block/qcow2.h index 5bd08db..01053b7 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -150,6 +150,12 @@ static inline int size_to_clusters(BDRVQcowState *s, int64_t size) return (size + (s->cluster_size - 1)) >> s->cluster_bits; } +static inline int size_to_l1(BDRVQcowState *s, int64_t size) +{ + int shift = s->cluster_bits + s->l2_bits; + return (size + (1ULL << shift) - 1) >> shift; +} + static inline int64_t align_offset(int64_t offset, int n) { offset = (offset + n - 1) & ~(n - 1); |