diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-05-16 13:56:53 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-05-18 14:39:15 +0200 |
commit | 77a5a0001bd9eaee9da7dc8f0b69702d56b0cc67 (patch) | |
tree | 653123f56af00a2005064b47ec81af6edeeedde6 | |
parent | f6a00aa150ec685966ca9453601328fdb2f87f34 (diff) |
qed: support for growing images
The .bdrv_truncate() operation resizes images and growing is easy to
implement in QED. Simply check that the new size is valid and then
update the image_size header field to reflect the new size.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r-- | block/qed.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/block/qed.c b/block/qed.c index d8d6ea2126..da0bf3127b 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1333,7 +1333,27 @@ static BlockDriverAIOCB *bdrv_qed_aio_flush(BlockDriverState *bs, static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset) { - return -ENOTSUP; + BDRVQEDState *s = bs->opaque; + uint64_t old_image_size; + int ret; + + if (!qed_is_image_size_valid(offset, s->header.cluster_size, + s->header.table_size)) { + return -EINVAL; + } + + /* Shrinking is currently not supported */ + if ((uint64_t)offset < s->header.image_size) { + return -ENOTSUP; + } + + old_image_size = s->header.image_size; + s->header.image_size = offset; + ret = qed_write_header_sync(s); + if (ret < 0) { + s->header.image_size = old_image_size; + } + return ret; } static int64_t bdrv_qed_getlength(BlockDriverState *bs) |