block/rbd: increase dynamically the image size
cover block/rbd: increase dynamically the image size
RBD APIs don't allow us to write more than the maximum size of the file set with rbd_create() or rbd_resize(), so we are not able to create/use a qcow2 image with the rbd driver.
What I found is the following:
- when qcow2 uses the rbd driver, the new file is created (rbd_create) with the size equals to 0. (qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) returns 0 in qemu_rbd_co_create_opts())
- the file is truncated (implemented with rbd_resize) to 0 before to write the qcow2 header.
- the "size" parameter passed to rbd_create() or rbd_resize() is interpreted as the maximum size of the file, this means that all writes that exceed that size, fails and returns -22.
As a workaround, I'm checking if the RW operations exceed the maximum size and then I'll resize the file. It works, but I'm not sure it is the right way.
Any suggestions?
Thanks,
Stefano
Stefano Garzarella (1):
block/rbd: increase dynamically the image size
block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Signature · 1 line
2.20.1
RFC PATCH 1/1 block/rbd: increase dynamically the image size
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 RW operations that exceed the current size.
--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
block/rbd.c +25 -0
@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState; static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {
@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations +* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } + + s->image_size = off + size; + } + acb->ret =0 ; acb->error =0 ; acb->s = s;
@@ -1066,6 +1089,8 @@ static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,return r; } + s->image_size = offset; +return 0 ; }
Signature · 1 line
2.20.1
Quoted 5 lines · Stefano Garzarella
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.
What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Quoted 67 lines
Signed-off-by Stefano Garzarella <[email protected]>--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)block/rbd.c +25
-1@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState; static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations +* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } + + s->image_size = off + size; + } + acb->ret =0 ; acb->error =0 ; acb->s = s;@@ -1066,6 +1089,8 @@ static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,return r; } + s->image_size = offset; +return 0 ; } --2.20.1
Signature · 1 line
Jason
Quoted 11 lines · Jason Dillaman
Quoted 5 lines · Stefano Garzarella
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Hi Jason,
I understand your point of view, maybe one use case could be if you have a qcow2 image and you want to put it in the rdb pool without convert it.
I'm going through this BZ [1] and I'll ask if they have other use cases in mind.
Anyway, if we want to support only raw format on RBD driver, maybe we should return something different from current behaviour, also avoiding to create the image:
$ qemu-img create -f qcow2 rbd:test/qcow.img 1G qemu-img: rbd:test/qcow.img: Could not write qcow2 header: Invalid argument
What do you think?
Thanks,
Stefano
Quoted 14 lines · Stefano Garzarella
Quoted 11 lines · Jason Dillaman
Quoted 5 lines · Stefano Garzarella
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Quoted 6 lines
Hi Jason,
I understand your point of view, maybe one use case could be if you have a qcow2 image and you want to put it in the rdb pool without convert it.I'm going through this BZ [1] and I'll ask if they have other use cases in mind.
Assuming no good use-cases, perhaps it would just be better to make the qemu-img error messages more clear.
Quoted 13 lines
Anyway, if we want to support only raw format on RBD driver, maybe we should return something different from current behaviour, also avoiding to create the image:
$ qemu-img create -f qcow2 rbd:test/qcow.img 1G qemu-img: rbd:test/qcow.img: Could not write qcow2 header: Invalid argumentWhat do you think?
Thanks,
Stefano
Signature · 1 line
Jason
Quoted 19 lines · Jason Dillaman
Quoted 18 lines · Stefano Garzarella
Quoted 11 lines · Jason Dillaman
Quoted 5 lines · Stefano Garzarella
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Hi Jason,
I understand your point of view, maybe one use case could be if you have a qcow2 image and you want to put it in the rdb pool without convert it.
Quoted 6 lines
Quoted 2 lines
I'm going through this BZ [1] and I'll ask if they have other use cases in mind.
Assuming no good use-cases, perhaps it would just be better to make the qemu-img error messages more clear.
Hi Jason,
I asked about use-cases and they want to use qcow2 on rbd in order to take advantage of these qcow2 features [1]: external snapshots, Copy-on-write, and optional compression and encryption.
Maybe the more interesting are external snapshots and Copy-on-write, since encryption can be achieved with LUKS and rbd should support compression for a specified pool.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1171007#c13
Cheers,
Stefano
Quoted 28 lines · Stefano Garzarella
Quoted 19 lines · Jason Dillaman
Quoted 18 lines · Stefano Garzarella
Quoted 11 lines · Jason Dillaman
Quoted 5 lines · Stefano Garzarella
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Hi Jason,
I understand your point of view, maybe one use case could be if you have a qcow2 image and you want to put it in the rdb pool without convert it.Quoted 6 lines
Quoted 2 lines
I'm going through this BZ [1] and I'll ask if they have other use cases in mind.
Assuming no good use-cases, perhaps it would just be better to make the qemu-img error messages more clear.
Quoted 6 lines
Hi Jason,
I asked about use-cases and they want to use qcow2 on rbd in order to take advantage of these qcow2 features [1]: external snapshots, Copy-on-write, and optional compression and encryption.Maybe the more interesting are external snapshots and Copy-on-write,
Copy-on-write is natively supported by RBD. The concept of external snapshots seems similar to just automating the process of creating a new copy-on-write image. Compression is also supported by Ceph on the cluster side by recent releases.
Quoted 7 lines
since encryption can be achieved with LUKS and rbd should support compression for a specified pool.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1171007#c13
Cheers,
Stefano
Signature · 1 line
Jason
Am 14.04.2019 um 17:14 hat Jason Dillaman geschrieben:
Quoted 34 lines · Stefano Garzarella
Quoted 33 lines · Jason Dillaman
Quoted 19 lines · Stefano Garzarella
Quoted 18 lines · Jason Dillaman
Quoted 11 lines · Stefano Garzarella
Quoted 5 lines
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.What's the use-case for storing qcow2 images within a RBD image? RBD images are already thinly provisioned, they support snapshots, they can form a parent/child linked image hierarchy.
Hi Jason,
I understand your point of view, maybe one use case could be if you have a qcow2 image and you want to put it in the rdb pool without convert it.Quoted 6 lines
Quoted 2 lines
I'm going through this BZ [1] and I'll ask if they have other use cases in mind.
Assuming no good use-cases, perhaps it would just be better to make the qemu-img error messages more clear.
Hi Jason,
I asked about use-cases and they want to use qcow2 on rbd in order to take advantage of these qcow2 features [1]: external snapshots, Copy-on-write, and optional compression and encryption.
Quoted 6 lines
Quoted 1 line
Maybe the more interesting are external snapshots and Copy-on-write,
Copy-on-write is natively supported by RBD. The concept of external snapshots seems similar to just automating the process of creating a new copy-on-write image. Compression is also supported by Ceph on the cluster side by recent releases.
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
How fast is rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.
Kevin
Quoted 5 lines · Kevin Wolf
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
Quoted 5 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.
I'll try to measure the percentage of the time spent in the rbd_resize.
Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Do you think make sense? Is it feasible?
Thanks,
Stefano
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Quoted 5 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.
Quoted 8 lines
I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that.
Kevin
Hi Kevin,
Quoted 14 lines · Kevin Wolf
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
Quoted 7 lines
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Very interesting, I'll try to add this support also in the rbd driver.
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Quoted 5 lines
Quoted 1 line
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that
I did some tests and it seems that the cost of rbd_resize() is negligible. IIUC it only updates the metadata without allocating any blocks (if we are growing, like that case).
Anyway the automatic resize will not affect the current use-case (raw images on rbd), where the file size is set during the creation, so I think there should not be side effects with this patch.
I'm also adding the support for preallocation (i.e. full) in the rbd driver that can be useful for qcow2 images.
If you prefer I can resend this patch with the preallocation series.
Thanks,
Stefano
Am 19.04.2019 um 14:23 hat Stefano Garzarella geschrieben:
Quoted 17 lines
Hi Kevin,
Quoted 14 lines · Kevin Wolf
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
Quoted 8 lines
Quoted 6 lines
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Very interesting, I'll try to add this support also in the rbd driver.
I don't understand - what is the thing you want to add to the rbd driver? qcow2 doesn't need special protocol driver support for doing this, and I don't think the QEMU rbd driver has any metadata that could be split off.
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Quoted 5 lines
Quoted 1 line
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that
Quoted 7 lines
I did some tests and it seems that the cost of
rbd_resize()is negligible. IIUC it only updates the metadata without allocating any blocks (if we are growing, like that case).Anyway the automatic resize will not affect the current use-case (raw images on rbd), where the file size is set during the creation, so I think there should not be side effects with this patch.
Okay, sounds good.
Quoted 4 lines
I'm also adding the support for preallocation (i.e. full) in the rbd driver that can be useful for qcow2 images.
If you prefer I can resend this patch with the preallocation series.
Let's keep seperate things separate. Huge patch series are always harder to handle.
Kevin
Quoted 25 lines · Kevin Wolf
Am 19.04.2019 um 14:23 hat Stefano Garzarella geschrieben:
Quoted 24 lines
Hi Kevin,
Quoted 20 lines · Kevin Wolf
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Quoted 6 lines
Quoted 1 line
Very interesting, I'll try to add this support also in the rbd driver.
I don't understand - what is the thing you want to add to the rbd driver? qcow2 doesn't need special protocol driver support for doing this, and I don't think the QEMU rbd driver has any metadata that could be split off.
Oh sorry, I didn't understand that was completely independent from the protocol.
Quoted 28 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Quoted 5 lines
Quoted 1 line
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that
Quoted 7 lines
I did some tests and it seems that the cost of
rbd_resize()is negligible. IIUC it only updates the metadata without allocating any blocks (if we are growing, like that case).Anyway the automatic resize will not affect the current use-case (raw images on rbd), where the file size is set during the creation, so I think there should not be side effects with this patch.
Okay, sounds good.
Quoted 7 lines
Quoted 4 lines
I'm also adding the support for preallocation (i.e. full) in the rbd driver that can be useful for qcow2 images.
If you prefer I can resend this patch with the preallocation series.
Let's keep seperate things separate. Huge patch series are always harder to handle.
Okay, thanks for the suggestion!
Should this patch go through your tree?
Thanks,
Stefano
Am 23.04.2019 um 10:26 hat Stefano Garzarella geschrieben:
Quoted 67 lines · Kevin Wolf
Quoted 25 lines
Am 19.04.2019 um 14:23 hat Stefano Garzarella geschrieben:
Quoted 24 lines
Hi Kevin,
Quoted 20 lines · Kevin Wolf
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Quoted 6 lines
Quoted 1 line
Very interesting, I'll try to add this support also in the rbd driver.
I don't understand - what is the thing you want to add to the rbd driver? qcow2 doesn't need special protocol driver support for doing this, and I don't think the QEMU rbd driver has any metadata that could be split off.
Oh sorry, I didn't understand that was completely independent from the protocol.
Quoted 31 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Quoted 5 lines
Quoted 1 line
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that
Quoted 7 lines
I did some tests and it seems that the cost of
rbd_resize()is negligible. IIUC it only updates the metadata without allocating any blocks (if we are growing, like that case).Anyway the automatic resize will not affect the current use-case (raw images on rbd), where the file size is set during the creation, so I think there should not be side effects with this patch.
Okay, sounds good.
Quoted 3 lines
I'm also adding the support for preallocation (i.e. full) in the rbd driver that can be useful for qcow2 images.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
If you prefer I can resend this patch with the preallocation series.
Let's keep seperate things separate. Huge patch series are always harder to handle.
Okay, thanks for the suggestion!
Should this patch go through your tree?
I think so, yes.
Kevin
Am 23.04.2019 um 10:38 hat Kevin Wolf geschrieben:
Quoted 70 lines
Am 23.04.2019 um 10:26 hat Stefano Garzarella geschrieben:
Quoted 69 lines · Kevin Wolf
Quoted 25 lines
Am 19.04.2019 um 14:23 hat Stefano Garzarella geschrieben:
Quoted 24 lines
Hi Kevin,
Quoted 20 lines · Kevin Wolf
Am 17.04.2019 um 09:34 hat Stefano Garzarella geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
I think a potential actual use case could be persistent dirty bitmaps for incremental backup. Though maybe that would be better served by using the rbd image just as a raw external data file and keeping the qcow2 metadata on a filesystem.
Thanks to point it out! I'll take a look to understand how to keep metadata separated from the data.
I'd consider the feature still experimental, but for local files, it works like this:
qemu-img create -f qcow2 -o data_file=test.raw test.qcow2 4G
And then just use test.qcow2. As long as you can put everything you need into an rbd URL, the same approach should work. Otherwise, you may need to use QMP blockdev-create on creation and possibly the data-file option of the qcow2 driver for opening.
Quoted 6 lines
Quoted 1 line
Very interesting, I'll try to add this support also in the rbd driver.
I don't understand - what is the thing you want to add to the rbd driver? qcow2 doesn't need special protocol driver support for doing this, and I don't think the QEMU rbd driver has any metadata that could be split off.
Oh sorry, I didn't understand that was completely independent from the protocol.
Quoted 33 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
How fast is
rbd_resize()? Does automatically resizing for every write request actually work reasonably well in practice? If it does, there is probably little reason not to allow it, even if the use cases are rather obscure.I'll try to measure the percentage of the time spent in the
rbd_resize.Another solution could be to pass to the rbd driver the virtual size of the image and resize it only one time also if the preallocation is disabled, because RBD will not allocate blocks but IIUC it only set the max size.
Quoted 5 lines
Quoted 1 line
Do you think make sense? Is it feasible?
In theory yes, though it requires modification of every driver that should be usable together with rbd (i.e. ideally all of the drivers). If automatic resize works good enough, I'd prefer that
Quoted 7 lines
I did some tests and it seems that the cost of
rbd_resize()is negligible. IIUC it only updates the metadata without allocating any blocks (if we are growing, like that case).Anyway the automatic resize will not affect the current use-case (raw images on rbd), where the file size is set during the creation, so I think there should not be side effects with this patch.
Okay, sounds good.
Quoted 4 lines
I'm also adding the support for preallocation (i.e. full) in the rbd driver that can be useful for qcow2 images.
If you prefer I can resend this patch with the preallocation series.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Let's keep seperate things separate. Huge patch series are always harder to handle.
Okay, thanks for the suggestion!
Should this patch go through your tree?
I think so, yes.
Hm, this is an RFC patch, which suggests that it wasn't originally meant to be merged as it is. Are you going to send a new version, or did it turn out to be exactly what we want and the "RFC" tag was a mistake?
Kevin
Quoted 4 lines · Kevin Wolf
Hm, this is an RFC patch, which suggests that it wasn't originally meant to be merged as it is. Are you going to send a new version, or did it turn out to be exactly what we want and the "RFC" tag was a mistake?
I put the "RFC" tag because I was not sure about this patch, but after your comments and some tests on the rbd_resize() impact, I think that it turns out exactly what we want.
If you agree, you can queue it as is.
Thanks,
Stefano
Am 11.04.2019 um 12:50 hat Stefano Garzarella geschrieben:
Quoted 16 lines
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.Signed-off-by Stefano Garzarella <[email protected]>--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)block/rbd.c +0
-0
block/rbd.c typedef struct BDRVRBDState { · line 106
Quoted 5 lines
block/rbd.c +1
-0@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState;
Can't we use bs->total_sectors instead of adding a new image_size field?
Quoted 23 lines
block/rbd.c +11
-0static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations
block/rbd.c static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, · line 945
Quoted 10 lines
block/rbd.c +10
-0+* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } + + s->image_size = off + size; + }
This doesn't check the request type, so it's actually not limited to RW operations, but even reads will try to resize the image. This is at least surprising. For regular files, file-posix extends the file for write requests, but for reads it returns a zeroed buffer without actually changing the file size.
Kevin
Quoted 12 lines · Kevin Wolf
Am 11.04.2019 um 12:50 hat Stefano Garzarella geschrieben:
Quoted 11 lines
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.Signed-off-by Stefano Garzarella <[email protected]>--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Quoted 12 lines
block/rbd.c typedef struct BDRVRBDState { · line 106
Quoted 10 lines
block/rbd.c +1
-0@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState;Can't we use
bs->total_sectorsinstead of adding a newimage_sizefield?
I'm not sure we can use bs->total_sectors. IIUC, for example, it doesn't take care of bytes used by QCOW2 metadata.
Quoted 32 lines
Quoted 32 lines
block/rbd.c +19
-0static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations +* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } +
Quoted 8 lines
block/rbd.c static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, · line 945
Quoted 2 lines
block/rbd.c +2
-0+ s->image_size = off + size; + }This doesn't check the request type, so it's actually not limited to RW operations, but even reads will try to resize the image. This is at least surprising. For regular files, file-posix extends the file for write requests, but for reads it returns a zeroed buffer without actually changing the file size.
Yes, I'll change the behaviour in the v2.
I did some tries (i.e. using qemu-io and reading more than bytes used) and the RBD driver didn't receive 'read' requests that exceed the current size, maybe because it is managed in the QCOW2 protocol, but of course I'll handle also in the RBD driver.
Thanks,
Stefano
Am 29.04.2019 um 16:04 hat Stefano Garzarella geschrieben:
Quoted 26 lines · Kevin Wolf
Quoted 12 lines
Am 11.04.2019 um 12:50 hat Stefano Garzarella geschrieben:
Quoted 11 lines
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.Signed-off-by Stefano Garzarella <[email protected]>--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)Quoted 12 lines
block/rbd.c typedef struct BDRVRBDState { · line 106
Quoted 10 lines
block/rbd.c +1
-0@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState;Can't we use
bs->total_sectorsinstead of adding a newimage_sizefield?
Quoted 2 lines
I'm not sure we can use
bs->total_sectors. IIUC, for example, it doesn't take care of bytes used by QCOW2 metadata.
bs->total_sectors for the rbd BLockDriverState is the image file size, not the virtual disk size.
The only reason not to use it would be if we need byte granularity rather than 512 byte granularity. But I don't think it's a problem to round up offsets to the next 512 bytes (BDRV_SECTOR_SIZE) boundary.
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
block/rbd.c +19
-0static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations +* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } +Quoted 8 lines
block/rbd.c static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, · line 945
Quoted 2 lines
block/rbd.c +2
-0+ s->image_size = off + size; + }This doesn't check the request type, so it's actually not limited to RW operations, but even reads will try to resize the image. This is at least surprising. For regular files, file-posix extends the file for write requests, but for reads it returns a zeroed buffer without actually changing the file size.
Quoted 6 lines
Yes, I'll change the behaviour in the v2.
I did some tries (i.e. using qemu-io and reading more than bytes used) and the RBD driver didn't receive 'read' requests that exceed the current size, maybe because it is managed in the QCOW2 protocol, but of course I'll handle also in the RBD driver.
I don't remember the exact scenario where it happened, but I know I implemented it for file-posix to fix a bug. Maybe it actually doesn't happen any more because we have made other changes in the meantime, but I'm not sure.
Kevin
Quoted 30 lines · Kevin Wolf
Am 29.04.2019 um 16:04 hat Stefano Garzarella geschrieben:
Quoted 26 lines · Kevin Wolf
Quoted 12 lines
Am 11.04.2019 um 12:50 hat Stefano Garzarella geschrieben:
Quoted 11 lines
RBD APIs don't allow us to write more than the size set with
rbd_create()orrbd_resize().
In order to support growing images (eg. qcow2), we resize the image before RW operations that exceed the current size.Signed-off-by Stefano Garzarella <[email protected]>--- block/rbd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)Quoted 12 lines
block/rbd.c typedef struct BDRVRBDState { · line 106
Quoted 10 lines
block/rbd.c +1
-0@@ -102,6 +102,7 @@ typedef struct BDRVRBDState {rbd_image_t image;char *image_name;char *snap; +uint64_t image_size; } BDRVRBDState;Can't we use
bs->total_sectorsinstead of adding a newimage_sizefield?Quoted 2 lines
I'm not sure we can use
bs->total_sectors. IIUC, for example, it doesn't take care of bytes used by QCOW2 metadata.
Quoted 7 lines
bs->total_sectorsfor the rbd BLockDriverState is the image file size, not the virtual disk size.The only reason not to use it would be if we need byte granularity rather than 512 byte granularity. But I don't think it's a problem to round up offsets to the next 512 bytes (
BDRV_SECTOR_SIZE) boundary.
I tried and it works as you told me :) I'll remove the image_size in the v2.
Quoted 47 lines
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
block/rbd.c +19
-0static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,@@ -777,6 +778,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, goto failed_open; } + r =rbd_get_size (s->image, &s->image_size); +if (r <0 ) { +error_setg_errno (errp, -r,"error reading image size from %s" , + s->image_name); +rbd_close (s->image); + goto failed_open; + } +/* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=NULL ) {@@ -921,6 +930,20 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, rcb->buf = acb->bounce; } +/* +* RBD APIs don't allow us to write more than actual size, so in order +* to support growing images, we resize the image before RW operations +* that exceed the current size. +*/ +if (s->image_size < off + size) { + r =rbd_resize (s->image, off + size); +if (r <0 ) { + goto failed; + } +Quoted 8 lines
block/rbd.c static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, · line 945
Quoted 2 lines
block/rbd.c +2
-0+ s->image_size = off + size; + }This doesn't check the request type, so it's actually not limited to RW operations, but even reads will try to resize the image. This is at least surprising. For regular files, file-posix extends the file for write requests, but for reads it returns a zeroed buffer without actually changing the file size.
Quoted 6 lines
Yes, I'll change the behaviour in the v2.
I did some tries (i.e. using qemu-io and reading more than bytes used) and the RBD driver didn't receive 'read' requests that exceed the current size, maybe because it is managed in the QCOW2 protocol, but of course I'll handle also in the RBD driver.
Quoted 5 lines
I don't remember the exact scenario where it happened, but I know I implemented it for file-posix to fix a bug. Maybe it actually doesn't happen any more because we have made other changes in the meantime, but I'm not sure.
Thanks for the details, I'll check better if we can avoid it, otherwise I'll take care of this in the RBD driver.
Cheers,
Stefano