qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block/rbd: fix write zeroes with growing images
@ 2022-03-17 16:26 Stefano Garzarella
  2022-03-17 18:27 ` Peter Lieven
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Stefano Garzarella @ 2022-03-17 16:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, qemu-block, Peter Lieven, Hanna Reitz, Ilya Dryomov,
	Stefano Garzarella

Commit d24f80234b ("block/rbd: increase dynamically the image size")
added a workaround to support growing images (eg. qcow2), resizing
the image before write operations that exceed the current size.

We recently added support for write zeroes and without the
workaround we can have problems with qcow2.

So let's move the resize into qemu_rbd_start_co() and do it when
the command is RBD_AIO_WRITE or RBD_AIO_WRITE_ZEROES.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2020993
Fixes: c56ac27d2a ("block/rbd: add write zeroes support")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 block/rbd.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index 8f183eba2a..6caf35cbba 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -1107,6 +1107,20 @@ static int coroutine_fn qemu_rbd_start_co(BlockDriverState *bs,
 
     assert(!qiov || qiov->size == bytes);
 
+    if (cmd == RBD_AIO_WRITE || cmd == RBD_AIO_WRITE_ZEROES) {
+        /*
+         * 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 (offset + bytes > s->image_size) {
+            int r = qemu_rbd_resize(bs, offset + bytes);
+            if (r < 0) {
+                return r;
+            }
+        }
+    }
+
     r = rbd_aio_create_completion(&task,
                                   (rbd_callback_t) qemu_rbd_completion_cb, &c);
     if (r < 0) {
@@ -1182,18 +1196,6 @@ coroutine_fn qemu_rbd_co_pwritev(BlockDriverState *bs, int64_t offset,
                                  int64_t bytes, QEMUIOVector *qiov,
                                  BdrvRequestFlags flags)
 {
-    BDRVRBDState *s = bs->opaque;
-    /*
-     * 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 (offset + bytes > s->image_size) {
-        int r = qemu_rbd_resize(bs, offset + bytes);
-        if (r < 0) {
-            return r;
-        }
-    }
     return qemu_rbd_start_co(bs, offset, bytes, qiov, flags, RBD_AIO_WRITE);
 }
 
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-03-24 11:36 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-17 16:26 [PATCH] block/rbd: fix write zeroes with growing images Stefano Garzarella
2022-03-17 18:27 ` Peter Lieven
2022-03-18  8:25   ` Stefano Garzarella
2022-03-18 15:48     ` Peter Lieven
2022-03-18 16:47       ` Stefano Garzarella
2022-03-19 15:15         ` Peter Lieven
2022-03-21  8:31           ` Stefano Garzarella
2022-03-22  9:38             ` Hanna Reitz
2022-03-24  9:52               ` Peter Lieven
2022-03-24 10:40                 ` Stefano Garzarella
2022-03-24 10:42                   ` Peter Lieven
2022-03-24 11:06                     ` Hanna Reitz
2022-03-24 11:34                       ` Peter Lieven
2022-03-19 12:40     ` Ilya Dryomov
2022-03-19 13:23       ` Ilya Dryomov
2022-03-21  8:17         ` Stefano Garzarella
2022-03-18 15:36 ` Hanna Reitz
2022-03-19 12:33 ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).