[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2] block/rbd: increase dynamically the image size
From: |
Stefano Garzarella |
Subject: |
[Qemu-block] [PATCH v2] block/rbd: increase dynamically the image size |
Date: |
Fri, 3 May 2019 18:30:28 +0200 |
RBD APIs don't allow us to write more than the size set with
rbd_create() or rbd_resize().
In order to support growing images (eg. qcow2), we resize the
image before write operations that exceed the current size.
Signed-off-by: Stefano Garzarella <address@hidden>
---
v2:
- use bs->total_sectors instead of adding a new field [Kevin]
- resize the image only during write operation [Kevin]
for read operation, the bdrv_aligned_preadv() already handles reads
that exceed the length returned by bdrv_getlength(), so IMHO we can
avoid to handle it in the rbd driver
---
block/rbd.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/block/rbd.c b/block/rbd.c
index 0c549c9935..613e8f4982 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -934,13 +934,25 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs,
}
switch (cmd) {
- case RBD_AIO_WRITE:
+ case RBD_AIO_WRITE: {
+ /*
+ * RBD APIs don't allow us to write more than actual size, so in order
+ * to support growing images, we resize the image before write
+ * operations that exceed the current size.
+ */
+ if (off + size > bs->total_sectors * BDRV_SECTOR_SIZE) {
+ r = rbd_resize(s->image, off + size);
+ if (r < 0) {
+ goto failed_completion;
+ }
+ }
#ifdef LIBRBD_SUPPORTS_IOVEC
r = rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c);
#else
r = rbd_aio_write(s->image, off, size, rcb->buf, c);
#endif
break;
+ }
case RBD_AIO_READ:
#ifdef LIBRBD_SUPPORTS_IOVEC
r = rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c);
--
2.20.1
- [Qemu-block] [PATCH v2] block/rbd: increase dynamically the image size,
Stefano Garzarella <=