All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com,
	xiechanglong.d@gmail.com, wencongyang2@huawei.com,
	hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru,
	jsnow@redhat.com, f.ebner@proxmox.com, den@virtuozzo.com,
	alexander.ivanov@virtuozzo.com
Subject: [PATCH v3 2/5] block/copy-before-write: support unligned snapshot-discard
Date: Wed, 28 Feb 2024 17:14:58 +0300	[thread overview]
Message-ID: <20240228141501.455989-3-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20240228141501.455989-1-vsementsov@yandex-team.ru>

First thing that crashes on unligned access here is
bdrv_reset_dirty_bitmap(). Correct way is to align-down the
snapshot-discard request.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 block/copy-before-write.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 3919d495d7..6547eda707 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -325,14 +325,24 @@ static int coroutine_fn GRAPH_RDLOCK
 cbw_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes)
 {
     BDRVCopyBeforeWriteState *s = bs->opaque;
+    uint32_t cluster_size = block_copy_cluster_size(s->bcs);
+    int64_t aligned_offset = QEMU_ALIGN_UP(offset, cluster_size);
+    int64_t aligned_end = QEMU_ALIGN_DOWN(offset + bytes, cluster_size);
+    int64_t aligned_bytes;
+
+    if (aligned_end <= aligned_offset) {
+        return 0;
+    }
+    aligned_bytes = aligned_end - aligned_offset;
 
     WITH_QEMU_LOCK_GUARD(&s->lock) {
-        bdrv_reset_dirty_bitmap(s->access_bitmap, offset, bytes);
+        bdrv_reset_dirty_bitmap(s->access_bitmap, aligned_offset,
+                                aligned_bytes);
     }
 
-    block_copy_reset(s->bcs, offset, bytes);
+    block_copy_reset(s->bcs, aligned_offset, aligned_bytes);
 
-    return bdrv_co_pdiscard(s->target, offset, bytes);
+    return bdrv_co_pdiscard(s->target, aligned_offset, aligned_bytes);
 }
 
 static void GRAPH_RDLOCK cbw_refresh_filename(BlockDriverState *bs)
-- 
2.34.1



  parent reply	other threads:[~2024-02-28 14:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 14:14 [PATCH v3 0/5] backup: discard-source parameter Vladimir Sementsov-Ogievskiy
2024-02-28 14:14 ` [PATCH v3 1/5] block/copy-before-write: fix permission Vladimir Sementsov-Ogievskiy
2024-02-28 14:14 ` Vladimir Sementsov-Ogievskiy [this message]
2024-03-08 15:49   ` [PATCH v3 2/5] block/copy-before-write: support unligned snapshot-discard Fiona Ebner
2024-02-28 14:14 ` [PATCH v3 3/5] block/copy-before-write: create block_copy bitmap in filter node Vladimir Sementsov-Ogievskiy
2024-03-08 15:49   ` Fiona Ebner
2024-02-28 14:15 ` [PATCH v3 4/5] qapi: blockdev-backup: add discard-source parameter Vladimir Sementsov-Ogievskiy
2024-03-08 15:49   ` Fiona Ebner
2024-02-28 14:15 ` [PATCH v3 5/5] iotests: add backup-discard-source Vladimir Sementsov-Ogievskiy
2024-03-08 15:49   ` Fiona Ebner
2024-03-08 15:49 ` [PATCH v3 0/5] backup: discard-source parameter Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240228141501.455989-3-vsementsov@yandex-team.ru \
    --to=vsementsov@yandex-team.ru \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=f.ebner@proxmox.com \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wencongyang2@huawei.com \
    --cc=xiechanglong.d@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.